package com.wanmait.schedule.controller;

import com.wanmait.schedule.entity.NoticeType;
import com.wanmait.schedule.service.NoticeTypeService;
import com.wanmait.schedule.util.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 通知类型表 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@RestController
@RequestMapping("/manage/noticeType")
@RequiresPermissions("manage:notice")
public class NoticeTypeController {
    @Resource
    NoticeTypeService noticeTypeService;

    //添加
   @PostMapping("save")
    public AjaxResult save(@RequestBody NoticeType noticeType){
      boolean flag= noticeTypeService.save(noticeType);
      if (flag) {
          return AjaxResult.success("添加成功");
      }
      return AjaxResult.error(10001,"添加失败");
   }

   //列表
    @GetMapping("list")
    public AjaxResult list(){
       return  AjaxResult.success("成功",noticeTypeService.list());

    }

    //修改
    @PostMapping("update")
    public AjaxResult update(@RequestBody NoticeType noticeType) {
        boolean flag = noticeTypeService.updateById(noticeType);
        if (flag) {
            return AjaxResult.success("修改成功");
        }
        return AjaxResult.error(10001,"修改失败");
    }
    //删除
    @GetMapping("delete")
    public AjaxResult delete(Integer id) {
        boolean flag = noticeTypeService.removeById(id);
        if (flag) {
            return AjaxResult.success("删除成功");
        }
        return AjaxResult.error(10001,"删除失败");
    }

}
